package com.ply.controller;

import com.ply.entity.vo.Result;
import com.ply.service.VisitUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @author XiaoPan
 * date: 2022/1/15 9:07
 * <p>
 * action:
 */
@RestController("/")
public class VisitUserController {

    @Autowired
    VisitUserService visitUserService;



    // todo optionId 不存在 没有解决
    @GetMapping("/api/toVote")
    public Result toVote(Integer optionId,HttpServletRequest request) {
        if (optionId < 0){
            return Result.fail("参数异常");
        }

        String ip = request.getRemoteAddr();
        return visitUserService.toVote(optionId, ip);
    }


    @GetMapping("/admin/ViewRecord")
    public Result<?> ViewRecord(int projectId) {
        return visitUserService.ViewRecord(projectId);
    }

}
